//
//  XHNetWorkManager.m
//  xinhua_sx
//
//  Created by 党阳阳 on 14-7-30.
//  Copyright (c) 2014年 dangyangyang. All rights reserved.
//

#import "XHNetWorkManager.h"
#import "AFNetworking.h"
#import "XHURLString.h"





@implementation XHNetWorkManager

+ (id)shareManager
{
    static dispatch_once_t once = 0;
    __strong static id sharedInstance = nil;
    dispatch_once(&once, ^{
        sharedInstance = [[XHNetWorkManager alloc] init];
    });
    return sharedInstance;
}
#pragma mark 登录

+ (RACSignal *)loginWithName:(NSString *)name PassWord:(NSString *)password
{
    
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    
        NSDictionary *params = @{@"name": name,@"password":password};
        [manager POST:[XHURLString getLoginString] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            [subscriber sendNext:responseObject];
         
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
            [subscriber sendNext:@"网络错误"];
            
        }];
       
        return nil;
    }];

}
@end
